package p08_bean的scope.不同scope的bean;

import lombok.Data;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 这是一个bean的作用域为application，生命周期跟容器的生命周期一样
 */
@Scope(value = "application")
@Component
public class ApplicationBean {
    private String name;

    public ApplicationBean() {
        this.name = System.currentTimeMillis() + "";
    }

    @PostConstruct
    public void init() {
        System.out.println("application被创建啦..." + name);
    }

    @PreDestroy
    public void destroy() {
        System.out.println("application被销毁啦..." + name);
    }

    @Override
    public String toString() {
        return "ApplicationBean{" +
                "name='" + name + '\'' +
                '}';
    }
}
